package com.example.bookKeep.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.bookKeep.entity.Book;
import com.example.bookKeep.mapper.BookMapper;
import com.example.bookKeep.request.BookListRequest;
import com.example.bookKeep.vo.BookHomeVO;
import com.example.bookKeep.vo.BookMonthDayNumVO;
import com.example.bookKeep.vo.StatisticsContainerVO;
import com.example.bookKeep.vo.StatisticsVO;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService extends ServiceImpl<BookMapper, Book> implements IService<Book> {

    public BookHomeVO homeStatistics(String ym) {
        if (StrUtil.isEmptyIfStr(ym)) {
            ym = DateUtil.thisYear() + "-" + (DateUtil.thisMonth() + 1);
        }
        return baseMapper.homeStatistics(ym);
    }

    public StatisticsContainerVO monthStatistics(String ym) {
        List<StatisticsVO> categoryStatisticsVOS = baseMapper.categoryMonthStatistics(ym);
        List<StatisticsVO> purchaserStatisticsVOS = baseMapper.purchaserMonthStatistics(ym);

        StatisticsContainerVO statisticsContainerVO = new StatisticsContainerVO();
        statisticsContainerVO.setCategory(categoryStatisticsVOS);
        statisticsContainerVO.setPurchaser(purchaserStatisticsVOS);
        return statisticsContainerVO;
    }

    public StatisticsContainerVO yearStatistics(String ym) {
        List<StatisticsVO> categoryStatisticsVOS = baseMapper.categoryYearStatistics(ym);
        List<StatisticsVO> purchaserStatisticsVOS = baseMapper.purchaserYearStatistics(ym);

        StatisticsContainerVO statisticsContainerVO = new StatisticsContainerVO();
        statisticsContainerVO.setCategory(categoryStatisticsVOS);
        statisticsContainerVO.setPurchaser(purchaserStatisticsVOS);
        return statisticsContainerVO;
    }

    public List<Book> listByRequest(BookListRequest bookListRequest) {
        return baseMapper.listByRequest(bookListRequest);
    }

    public List<Book> listByMonth(String ym) {
        return baseMapper.listByMonth(ym);
    }

    public List<Book> listByYear(String y) {
        return baseMapper.listByYear(y);
    }

    public List<String> listPurchaser() {
        return baseMapper.listPurchaser();
    }

    public List<String> listDirector() {
        return baseMapper.listDirector();
    }

    public List<BookMonthDayNumVO> monthDayNum(String ym) {
        return baseMapper.monthDayNum(ym);
    }
}
